import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-07-28
 * 21:07
 */
class MinStack {

    public Stack<Integer> stack1;
    public Stack<Integer>  MinStack;

    public MinStack() {
        stack1=new Stack<>();
        MinStack=new Stack<>();
    }

    public void push(int val) {
        stack1.push(val);
        if(MinStack.isEmpty()){
            MinStack.push(val);
        }else {
            if(val<=MinStack.peek()){
                MinStack.push(val);
            }
        }
    }

    public void pop() {
        if(stack1.isEmpty()){
            return;
        }
        int peekVal=stack1.peek();
        if(peekVal==MinStack.peek()){
            stack1.pop();
            MinStack.pop();
        }else {
            stack1.pop();
        }
    }

    public int top() {
        if(stack1.isEmpty()){
            return -1;
        }
        return stack1.peek();
    }

    public int getMin() {
        if(MinStack.isEmpty()){
            return -1;
        }
        return MinStack.peek();
    }
}